const Utils = require("./utils.js")
const Evt = require("./event.js")
const Grid = require("./grid.js")
const {EN} = require("./constant.js")

module.exports = class Toolbar extends Evt{
	constructor($env,$event){
		super($env,$event)
		this.$event = $event;
		this.$env = $env;

		this.$dom = Utils.createDOM("div",{
			id:"draw-tool-bar",
			class:"draw-tool-bar"
		})

		this.$event.emit(EN.append,this.$dom)

		this.defaultPlugins={
			Grid 
		}
		this.bind()

		setTimeout(()=>{
			this.loadDefaultPlugins()
		})
	}
	loadDefaultPlugins(){
		let plugins = this.defaultPlugins;
		for(let k in plugins){
			plugins[k] = new plugins[k](this.$env,this.$event)
		}
	}
	bind(){
		this.$event.on(EN.plugin_append,(dom)=>{
			Utils.query("#"+dom.id)||this.$dom.appendChild(dom)
		})
	}
}
